
<#include "../global/header_landing.html">
<script type="text/javascript">
    $(document).ready(function () {
        $('#header_action').append('注册新用户');
    });
</script>

<div class="aw-register-box">
    <form class="aw-register-form" action="/signup" method="post" id="register_form">
        <ul>
            <li class="alert alert-danger hide error_message">
                <i class="fa fa-times"></i> <em></em>
            </li>
            <li>
                <input class="aw-register-name form-control" type="text" name="user_name" placeholder="用户名" tips="请输入一个 2-14 位的用户名，不能为纯数字" errortips="用户名长度不符合" value="" righttips=""/>
            </li>
            <li>
                <input class="aw-register-email form-control" type="text" placeholder="邮箱" name="email" tips="请输入你常用的电子邮箱作为你的账号" value="" errortips="邮箱格式不正确" righttips="邮箱格式正确" />
            </li>
            <li>
                <input class="aw-register-pwd form-control" type="password" name="password" id="password" placeholder="密码" tips="请输入 6-16 个字符，区分大小写" errortips="密码不符合规则" righttips="密码符合"/>
            </li>
            <li>
                <input class="aw-register-pwd form-control" type="password"  name="pwd" placeholder="重复密码" tips="请再次输入密码，确保两次密码相同" errortips="两次密码不相同" righttips="两次密码相同"/>
            </li>
            <li>
                <input class="aw-register-phone form-control" type="text" name="phone" placeholder="移动电话" tips="请输入11位移动电话号码,如:12345678901" errortips="电话不符合规则" righttips="电话正确"/>
            </li>
            <li>
                <input class="aw-register-website form-control" type="text" name="website" placeholder="公司网址" tips="请输入公司网站地址,如：http://zbmao.cn" errortips="出入网址不符合规则" righttips="网址正确"/>
            </li>
            <li class="aw-register-verify">
                <img class="pull-right" id="captcha" onclick="reload_captcha();" src="" />
                <input type="text" class="form-control" name="seccode_verify" placeholder="验证码" tips="验证码不区分大小写,点击图片可换一张" maxlength="4" />
            </li>
            <li class="last">
                <label><input type="checkbox" checked="checked" value="agree" name="agreement_chk" /> 我同意</label> <a href="javascript:;" onclick="$('.aw-regiter-agreement').show();">用户协议</a>
                <a href="/login/" class="pull-right">已有账号?</a>
                <div class="aw-regiter-agreement hide">
                    <div class="aw-register-agreement-txt" id="register_agreement"></div>
                </div>

            </li>
            <li class="clearfix">
                <button class="pull-right btn btn-large btn-success" onclick="ajax_post($('#register_form'), _error_message_form_processer); return false;">注册</button>
            </li>
        </ul>
    </form>
</div>

<script type="text/javascript">
    $(document).ready(function ()
    {
        $.get(G_BASE_URL + 'account/ajax/register_agreement/', function (result) { $('#register_agreement').html(result.err); }, 'json');

        $('.more-information-btn').click(function()
        {
            if ($('.more-information').is(':visible'))
            {
                $('.more-information').slideUp();
                $(this).find('i').removeClass('fa-chevron-up');
                $(this).find('i').addClass('fa-chevron-down');
            }
            else
            {
                $('.more-information').slideDown();
                $(this).find('i').removeClass('fa-chevron-down');
                $(this).find('i').addClass('fa-chevron-up');
            }
        });

        verify_register_form('#register_form');

        /* 注册页面验证 */
        function verify_register_form(element)
        {
            $(element).find('[type=text], [type=password]').on({
                focus : function()
                {
                    if (typeof $(this).attr('tips') != 'undefined' && $(this).attr('tips') != '')
                    {
                        $(this).parent().append('<span class="aw-reg-tips">' + $(this).attr('tips') + '</span>');
                    }
                },
                blur : function()
                {
                    if ($(this).attr('tips') != '')
                    {
                        switch ($(this).attr('name'))
                        {
                            case 'user_name' :
                                var _this = $(this);
                                $(this).parent().find('.aw-reg-tips').detach();
                                if ($(this).val().length >= 0 && $(this).val().length < 2)
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                if ($(this).val().length > 17)
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                else
                                {
                                    $.get(G_BASE_URL + 'account/ajax/check_username/username' + '-' + encodeURIComponent($(this).val()), function (result)
                                    {
                                        if (result.errno == -1)
                                        {
                                            _this.parent().find('.aw-reg-tips').detach();
                                            _this.parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + result.err + '</span>');
                                        }
                                        else
                                        {
                                            _this.parent().find('.aw-reg-tips').detach();
                                            _this.parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i>'+result.err+'</span>');
                                        }
                                    }, 'json');
                                }
                                return;

                            case 'email' :
                                $(this).parent().find('.aw-reg-tips').detach();
                                var emailreg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
                                if (!emailreg.test($(this).val()))
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                else
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i>'+$(this).attr('righttips')+'</span>');
                                }
                                return;

                            case 'password' :
                                $(this).parent().find('.aw-reg-tips').detach();
                                if ($(this).val().length >= 0 && $(this).val().length < 6)
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                if ($(this).val().length > 17)
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                else
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i>'+$(this).attr('righttips')+'</span>');
                                }
                                return;
                            case "pwd":
                                $(this).parent().find('.aw-reg-tips').detach();

                                if( $(this).val()!=$("#password").val()){
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }else{
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i>'+$(this).attr('righttips')+'</span>');
                                }
                                return;
                            case 'phone' :
                                $(this).parent().find('.aw-reg-tips').detach();
                                var phonereg = /^\d{11}$/;
                                if (!phonereg.test($(this).val()))
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                else
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i>'+$(this).attr('righttips')+'</span>');
                                }
                                return;

                            case 'website' :
                                $(this).parent().find('.aw-reg-tips').detach();
                                var phonereg = /^[a-zA-z]+:\/\/[^\s]*$/;
                                if (!phonereg.test($(this).val()))
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                else
                                {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i>'+$(this).attr('righttips')+'</span>');
                                }
                                return;
                        }
                    }

                }
            });
        }


    });
</script>

<#include "../global/footer.html">